package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.service.IEmployeeService;
import cn.wolfcode.wms.util.UserContext;
import cn.wolfcode.wms.vo.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService service;

    @RequestMapping("/login")
    @ResponseBody
    public JSONResult login(String userName, String password) {
        System.out.println("nihao");
        try {
            service.login(userName, password);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return JSONResult.success("登陆成功");
    }
    @RequestMapping("main")
    public String main(){
        return "main";
    }
    @RequestMapping("logout")
    public String logout(){
        UserContext.setCurrentUser(null);
        return "redirect:/static/login.html";
    }
}
